package com.guli.generator.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guli.generator.pojo.EduTeacher;
import com.guli.generator.pojo.vo.TeacherQuery;
import com.guli.generator.service.EduTeacherService;
import com.gulicom.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Controller
@CrossOrigin
@RequestMapping("/eduservice/teacher")
public class EduTeacherController {
    @Resource
    private EduTeacherService teacher;
    @PostMapping("/pageTeacherCondition/{current}/{limit}")
    @ResponseBody
    public R eduTeacherList(@PathVariable Integer current, @PathVariable Integer limit,@RequestBody(required = false) TeacherQuery teacherQuery){
        Page<EduTeacher> page = teacher.teacherList(current,limit,teacherQuery);
        List<EduTeacher> list = page.getRecords();
        Long total = page.getTotal();
        return R.ok().data("teacher",list).data("total",total);
    }
    @DeleteMapping("delete/{id}")
    @ResponseBody
    public R eduDeleTeacher(@PathVariable String id){
        Integer count = teacher.deleTeacher(id);
        if(count>0){
            return R.ok();
        }
        return R.error();
    }
    @PostMapping("/addTeacher")
    @ResponseBody
    public R addTeacherTest(@RequestBody EduTeacher eduTeacher){
        Integer count = teacher.addTeacher(eduTeacher);
        if(count>0){
           return R.ok();
        }
        return R.error();
    }
    @GetMapping("/getTeacher/{id}")
    @ResponseBody
    public R getTeacherText(@PathVariable String id){
        EduTeacher eduTeacher = teacher.getTeacher(id);
        if(eduTeacher!=null){
            return R.ok().data("teacher",eduTeacher);
        }
       return R.error();
    }
    @PostMapping("/updateTeacher")
    @ResponseBody
    public R updateTeacherText(@RequestBody EduTeacher eduTeacher){
        Integer count = teacher.updateTeacher(eduTeacher);
        if(count>0){
           return R.ok();
        }
        return R.error();
    }
}
